package com.tony.mulitithread.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.concurrent.*;

@Configuration
public class ThreadPoolConfig {
    //核心线程数
    private volatile int corePoolSize = 10;
    //最大线程数
    private volatile int maximumPoolSize = 30;
    //空闲线程最大存活时间
    private volatile int keepAliveTime = 100;
    //阻塞队列
    private static final BlockingDeque defaultBlockDeque = new LinkedBlockingDeque(100000);
    //默认的拒绝策略
    private static final RejectedExecutionHandler defaultHandler =
            new ThreadPoolExecutor.AbortPolicy();
    @Bean(name = "ScmThreadPoolExecutor")
    public ThreadPoolExecutor getThreadPoolTaskExecutor(){
        ThreadPoolExecutor threadPoolExecutor =
                new ThreadPoolExecutor(corePoolSize,maximumPoolSize,keepAliveTime,
                        TimeUnit.SECONDS,defaultBlockDeque,defaultHandler);
        return threadPoolExecutor;
    }
}
